package com.ares.aler.service.impl;

import com.ares.aler.entiy.AdminnavPo;
import com.ares.aler.entiy.NavPo;
import com.ares.aler.mapper.AdminnavPoMapper;
import com.ares.aler.service.AdminNavDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdminNavDaoImpl implements AdminNavDao {
    @Autowired
    AdminnavPoMapper adminnavPoMapper ;
    @Override
    public List<Map<String, Object>> navTree() {
        List<AdminnavPo> listPo = adminnavPoMapper.selectByPid("0");
        List<Map<String, Object>> firstList = new ArrayList<>();

        for(int i=0;i<listPo.size();i++){
            AdminnavPo adminnavPo = listPo.get(i);
            Map<String,Object> firstMap = new HashMap<>();
            firstMap.put("adminnavPo",adminnavPo);
            firstList.add(firstMap);
        }

        for(Map map1 : firstList){
            AdminnavPo adminnavPo = (AdminnavPo) map1.get("adminnavPo");
            String pid = adminnavPo.getId();
            //获取二级菜单
            List<Map<String, Object>>  secondList = new ArrayList<>();
            Map<String,Object> secondMap = new HashMap<>();
            List<AdminnavPo> secondPo = adminnavPoMapper.selectByPid(pid);
            secondMap.put("secondPo",secondPo);
            secondList.add(secondMap);
            map1.put("second", secondList);
        }

        return firstList;
    }
}
